﻿Ext.define('NMC.controller.NavigationController', {
    extend: 'Ext.app.Controller',

    views: ['PanelPrincipal'],

    refs: [
        {
            ref: 'panelPrincipal',
            selector: 'panel'
        }
    ],

    init: function() {
        this.control({
            'viewport > panelPrincipal button[action=administration]': {
                click: this.openAdministration
            },
            'viewport > panelPrincipal button[action=referentiel]': {
                click: this.openReferentiel
            },
			'viewport > panelPrincipal button[action=collections]': {
                click: this.openCollections
            },
			'viewport > panelPrincipal > panelAdministration button[action=utilisateurs]': {
                click: this.openUsers
            },
			'viewport > panelPrincipal > panelAdministration button[action=groupes]': {
                click: this.openGroupes
            }
        });
    },
	
	// Ouvrir le panneau d'administration
	openAdministration: function(button) {
		var panel = Ext.widget('panelAdministration');
		this.replaceComponentContent(Ext.getCmp('panelPrincipal'),panel);
                
                
    },
	
	// Ouvrir le panneau référentiel
	openReferentiel: function(button) {
		var panel = Ext.widget('panelReferentiel');
		this.replaceComponentContent(Ext.getCmp('panelPrincipal'),panel);
    },
	
	// Ouvrir le panneau Collections
	openCollections: function(button) {
		var panel = Ext.widget('panelCollections');
		this.replaceComponentContent(Ext.getCmp('panelPrincipal'),panel);
    },
	
	// Ouvrir le panneau Users
	openUsers: function(button) {
		var panel = Ext.widget('panelAdmUser');
		this.replaceComponentContent(Ext.getCmp('panelAdministration'),panel);
    },
	
	// Ouvrir le panneau Groupes
	openGroupes: function(button) {
		var panel = Ext.widget('panelAdmGroup');
		this.replaceComponentContent(Ext.getCmp('panelAdministration'),panel);
    },
	
	
	
	// Vider le panel fourni
	clearExtjsComponent : function(cmp) {
		var f;
		while(f = cmp.items.first()){
			cmp.remove(f, true);
		}
	},
	
	// Remplacer le contenu de cmpParent par cmpContent
	replaceComponentContent : function(cmpParent, cmpContent) {
		this.clearExtjsComponent(cmpParent);
		cmpParent.add(cmpContent);
		cmpParent.doLayout();
	}	
	

});
